Skip to content

fix(daily-cache): stop token-only slices inflating day totals on merge - #1788

Merged
iamtoruk merged 1 commit into
mainfrom
fix/daily-cache-token-inflation
Oct 26, 2026
Merged

iamtoruk merged 1 commit into
mainfrom
fix/daily-cache-token-inflation

Conversation

@iamtoruk

@iamtoruk iamtoruk commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Token totals on some days grow with every cache version bump.

A slice with tokens but no calls, cost or savings (a Hermes or Copilot session total) was treated as a placeholder. On every adoption or re-derive merge it was replaced while its tokens were added to the day and model rows again, so each bump multiplied them by the number of older cache files holding that day.

  • hasSliceData counts tokens as slice data.
  • subtractSlice still drops a token-only remainder, as before: it can be drift between two scans or usage whose source is gone, and nothing there tells which.
  • On load, day and model-row tokens are capped at the sum of the slices, but only for days whose calls and cost match their slices (this bug's fingerprint), so caches already inflated heal without a version bump and days that disagree for other reasons are left alone.

A newer token-only slice now wins over an older one with calls, as the newer-wins rule intends, instead of the two being added.

Rebased on #1786 (cache v76). No version bump of its own. This must ship in the same release as #1786: the move to v76 adopts every older cache file a 0.9.27 user has, which is exactly the merge that inflated.

Tests: three new cases in tests/daily-cache-carry-forward.test.ts; typecheck and the 39 suites that import the daily cache pass (548 tests).

Real data on this Mac (isolated cache and config dirs, sources read-only):

Scenario, 180 days main this branch
Real sources identical to this branch identical to main
Cache files only, 28 Aug (Hermes token-only slice held by 10 files) +26.2M tokens, +55.4M after one more bump exact
Main's inflated file loaded as current, or adopted as an older file heals to the clean figure, 0 differences
Old UTC-era file with 4 days whose calls and cost also disagree left untouched

Cost and calls are identical between main and this branch on every day in every scenario.

@ozymandiashh ozymandiashh added area: cli The codeburn CLI and its core parsing/reporting engine bug Something isn't working needs-real-data-proof PR needs screenshot or output proving it works against real data needs-validation PR requires validation against real-world usage before review labels Oct 24, 2026
@iamtoruk iamtoruk added validated Validated against real-world usage, ready for review and removed needs-real-data-proof PR needs screenshot or output proving it works against real data needs-validation PR requires validation against real-world usage before review labels Oct 26, 2026
A slice with tokens but no calls, cost or savings (a Hermes or Copilot
session total) read as a placeholder, so every adoption or re-derive merge
replaced it while adding its tokens to the day and model rows again. Each
version bump multiplied them by the number of older cache files holding
the day. Count tokens as slice data, and cap day and model-row tokens at
the slices' sum on load for days whose calls and cost match their
slices, this bug's fingerprint, so caches already inflated heal without
a version bump.
A newer token-only slice now wins over an older one with calls, as the
newer-wins rule intends, instead of the two being added.
@iamtoruk
iamtoruk force-pushed the fix/daily-cache-token-inflation branch from d5b22a3 to abae3c2 Compare October 26, 2026 02:49
@iamtoruk
iamtoruk merged commit de08cee into main Oct 26, 2026
23 checks passed
@iamtoruk
iamtoruk deleted the fix/daily-cache-token-inflation branch October 26, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli The codeburn CLI and its core parsing/reporting engine bug Something isn't working validated Validated against real-world usage, ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants